package com.zzhou.common.library.util;

import android.annotation.SuppressLint;

import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * <desc>
 * Created by The Moss on 2018/10/9.
 */

@SuppressLint({"SimpleDateFormat"})
public class DateUtils {
    public DateUtils() {
    }

    public static String getStringDate(Date currentTime) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(currentTime);
        return dateString;
    }

    public static String getStringDateHHmmss(Date currentTime) {
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
        String dateString = formatter.format(currentTime);
        return dateString;
    }

    public static String getStringDateMMdd(Date currentTime) {
        SimpleDateFormat formatter = new SimpleDateFormat("MM-dd HH:mm:ss");
        String dateString = formatter.format(currentTime);
        return dateString;
    }

    public static String getMMddFormat(long currentTime) {
        Calendar rightNow = Calendar.getInstance();
        int year = rightNow.get(Calendar.YEAR);
        rightNow.setTimeInMillis(currentTime * 1000L);
        int dateYear = rightNow.get(Calendar.YEAR);
        String dateString = null;
        SimpleDateFormat formatter;
        if(year == dateYear) {
            formatter = new SimpleDateFormat("MM 月 dd 日");
            dateString = formatter.format(new Date(currentTime * 1000L));
        } else {
            formatter = new SimpleDateFormat("yyyy 年 MM 月 dd 日");
            dateString = formatter.format(new Date(currentTime * 1000L));
        }

        return dateString;
    }

    public static String getMMddFormat1(long currentTime) {
        Calendar rightNow = Calendar.getInstance();
        rightNow.setTimeInMillis(currentTime * 1000L);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String dateString = formatter.format(new Date(currentTime * 1000L));
        return dateString;
    }

    public static String getStringDateHHmm(Date currentTime) {
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");
        String dateString = formatter.format(currentTime);
        return dateString;
    }

    public static Date strToDateLong(String strDate) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(strDate, pos);
        return strtodate;
    }

    public static Date strToDateLong1(String strDate) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(strDate, pos);
        return strtodate;
    }

    public static int getTimeDifferenceMinute(Date m_LastDate, Date m_NowDate) {
        return (int)(m_NowDate.getTime() - m_LastDate.getTime()) / '\uea60';
    }

    public static int getTimeDifferenceSeconds(Date m_LastDate, Date m_NowDate) {
        return (int)(m_NowDate.getTime() - m_LastDate.getTime()) / 1000;
    }

    public static Date getCurrentDate() {
        return new Date();
    }

    public static int getCurrentSecond() {
        return (int)(System.currentTimeMillis() / 1000L);
    }

    public static int getTimeOfSeconde(String user_time) {
        int re_time = 0;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");

        try {
            Date d = sdf.parse(user_time);
            long millisecond = d.getTime();
            re_time = (int)(millisecond / 1000L);
        } catch (ParseException var6) {
            var6.printStackTrace();
        }

        return re_time;
    }

    public static String getTimeLengh(int seconds) {
        int hour = seconds / 3600;
        int minute = seconds % 3600 / 60;
        int second = seconds % 60;
        return (hour > 9?Integer.valueOf(hour):"0" + hour) + ":" + (minute > 9?Integer.valueOf(hour):"0" + minute) + ":" + (second > 9?Integer.valueOf(second):"0" + second);
    }
}
